from django33.contrib.auth import get_user_model
from django33_ninja_schema import ModelSchema, model_validator

# 获取用户模型
UserModel = get_user_model()

# 新用户
new_user = UserModel.objects.create_user(
    username='zhangdapeng',
    email='zhangdapeng@example.com',
    password='zhangdapeng520',
    first_name='dapeng',
    last_name='zhang',
)


class UpdateUserSchema(ModelSchema):
    class Config:
        model = UserModel
        include = ['first_name', 'last_name', 'username']
        optional = ['username']  # 用户名是可选的


schema = UpdateUserSchema(first_name='dapeng', last_name='zhang')
# 合并两个schema
schema.apply(new_user, exclude_none=True)
